package com.redhat.auth.log.parse;

import java.util.Map;

/**
 * 此对象封装着一个主键对象
 * @author lingen.liu
 *
 */
public class KeyValue {

	private String keyId;
	
	private ParamType keyType;
	
	private int paramIndex;
	
	private String[] express;
	
	private String typeConv;
	
	public KeyValue(String keyValue){
		if(keyValue.indexOf("(")!=-1){
			typeConv = typeConv.substring(1,typeConv.indexOf(""));
		}
		//key flightId = arg[0]:flightId 或 flightId = return:flightId 或 thisClass:flightId
		String[] values = keyValue.split("=");
		keyId = values[0].trim();
		String[] params = values[1].split("\\.");
		if(values[1].trim().startsWith("arg")){
			keyType = ParamType.argType;
			paramIndex = Integer.parseInt(params[0].substring(params[0].indexOf("[")+1, params[0].indexOf("]")));
		}else if(values[1].trim().startsWith("return")){
			keyType = ParamType.returnType;
		}else if(values[1].trim().startsWith("thisClass")){
			keyType = ParamType.classType;
		}else if(values[1].trim().startsWith("cons")){
			keyType = ParamType.consType;
		}else{
			throw new RuntimeException("value defined wrong:"+keyValue);
		}
		express = new String[params.length-1];
		System.arraycopy(params, 1, express, 0, params.length-1);
	}

	public String getKeyId() {
		return keyId;
	}

	public void setKeyId(String keyId) {
		this.keyId = keyId;
	}

	public ParamType getKeyType() {
		return keyType;
	}

	public void setKeyType(ParamType keyType) {
		this.keyType = keyType;
	}

	public String[] getExpress() {
		return express;
	}

	public void setExpress(String[] express) {
		this.express = express;
	}
	
	public int getParamIndex() {
		return paramIndex;
	}

	public void setParamIndex(int paramIndex) {
		this.paramIndex = paramIndex;
	}

	public static void main(String args[]){
		KeyValue keyValue =  new KeyValue("flightId = cons:23");
		Map<Thread, StackTraceElement[]> threads = Thread.getAllStackTraces();
		
	}
}
